import org.deep.CmdManager;
import org.deep.cmd.CheckException;
import org.deep.cmd.HandleException;
import org.deep.cmd.TimeOutException;

import static org.deep.cmd.BaseCmd.calcSumValue;

public class Main {
    private static MockCmdSource mockCmdSource;

    public static void main(String[] args) {
        mockCmdSource = new MockCmdSource(buf -> {
            if (buf[0] == (byte) 0xbb && buf[1] == 0x01) {
                try {
                    Thread.sleep(20000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                byte[] result = new byte[32];
                result[0] = (byte) 0xbb;
                result[1] = 0x01;
                result[2] = 0x01;
                result[30] = (byte) 0xff;
                result[31] = calcSumValue(result);
                return result;
            }
            return new byte[0];
        });
        testSingleCmd();
    }

    private static void testSingleCmd() {
        try {
            Boolean result = CmdManager.INSTANCE.send(mockCmdSource, new MockSingleCmd(32, 3, 1000));
            assert result;
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
